package com.ruoyi.web.controller.fantasy;

import java.util.List;

import com.ruoyi.fantasy.domain.FantasyNpcPosition;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fantasy.service.IFantasyNpcPositionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * npc位置 信息操作处理
 * 
 * @author wanghui
 * @date 2019-08-02
 */
@Controller
@RequestMapping("/fantasy/fantasyNpcPosition")
public class FantasyNpcPositionController extends BaseController
{
    private String prefix = "fantasy/fantasyNpcPosition";
	
	@Autowired
	private IFantasyNpcPositionService fantasyNpcPositionService;
	
	@RequiresPermissions("fantasy:fantasyNpcPosition:view")
	@GetMapping()
	public String fantasyNpcPosition()
	{
	    return prefix + "/fantasyNpcPosition";
	}
	
	/**
	 * 查询npc位置列表
	 */
	@RequiresPermissions("fantasy:fantasyNpcPosition:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(FantasyNpcPosition fantasyNpcPosition)
	{
		startPage();
        List<FantasyNpcPosition> list = fantasyNpcPositionService.selectFantasyNpcPositionList(fantasyNpcPosition);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出npc位置列表
	 */
	@RequiresPermissions("fantasy:fantasyNpcPosition:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FantasyNpcPosition fantasyNpcPosition)
    {
    	List<FantasyNpcPosition> list = fantasyNpcPositionService.selectFantasyNpcPositionList(fantasyNpcPosition);
        ExcelUtil<FantasyNpcPosition> util = new ExcelUtil<FantasyNpcPosition>(FantasyNpcPosition.class);
        return util.exportExcel(list, "fantasyNpcPosition");
    }
	
	/**
	 * 新增npc位置
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存npc位置
	 */
	@RequiresPermissions("fantasy:fantasyNpcPosition:add")
	@Log(title = "npc位置", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(FantasyNpcPosition fantasyNpcPosition)
	{		
		return toAjax(fantasyNpcPositionService.insertFantasyNpcPosition(fantasyNpcPosition));
	}

	/**
	 * 修改npc位置
	 */
	@GetMapping("/edit/{positionId}")
	public String edit(@PathVariable("positionId") Long positionId, ModelMap mmap)
	{
		FantasyNpcPosition fantasyNpcPosition = fantasyNpcPositionService.selectFantasyNpcPositionById(positionId);
		mmap.put("fantasyNpcPosition", fantasyNpcPosition);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存npc位置
	 */
	@RequiresPermissions("fantasy:fantasyNpcPosition:edit")
	@Log(title = "npc位置", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(FantasyNpcPosition fantasyNpcPosition)
	{		
		return toAjax(fantasyNpcPositionService.updateFantasyNpcPosition(fantasyNpcPosition));
	}
	
	/**
	 * 删除npc位置
	 */
	@RequiresPermissions("fantasy:fantasyNpcPosition:remove")
	@Log(title = "npc位置", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(fantasyNpcPositionService.deleteFantasyNpcPositionByIds(ids));
	}
	
}
